package slstone.common.interceptor;

import java.util.Map;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

/**
 * 사용자 로그인 검증 Interceptor 이다.
 **/
public class AuthInterceptor extends AbstractInterceptor
{

	public String intercept(ActionInvocation actionInvocation) throws Exception
	{
		// 检查Session中是否存在user
		Map<String, Object> session = actionInvocation.getInvocationContext().getSession();

		if (session.get("userId") == null || "".equals(session.get("userId")))
		{
			// 否则终止后续操作，返回LOGIN
			return Action.INPUT;
		}
		else
		{
			// 存在的情况下进行后续操作
			return actionInvocation.invoke();
		}
	}
}
